﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Threading;
using WPFExcelReport;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXBL
    {
        public void AutoConvert(string path, string JobType)
        {
            ThreadStart Work = null;
            Thread Thread = null;
            if (IsRun)
                return;
            switch (JobType)
            {
                case "YGRMUZT":
                    Work = new ThreadStart(DoYGRMUZTWork);
                    break;
                case "JLTAB50MU":
                    Work = new ThreadStart(DoJLTAB50MUWork);
                    break;
                case "JLTAV95":
                    Work = new ThreadStart(DoJLTAV95Work);
                    break;
                case "YGRAV95":
                    Work = new ThreadStart(DoYGRAV95Work);
                    break;
                case "YGRAB50C":
                    Work = new ThreadStart(DoYGRAB50CWork);
                    break;
                case "ITXPDC":
                    Work = new ThreadStart(DoITXPDCWork);
                    break;
                case "YGRCPGB04":
                    Work = new ThreadStart(DoYGRCPGB04Work);
                    break;

            }
            Thread = new Thread(Work);
            Thread.Start();
        }
        public void Save2Xml(DataSet src, string path)
        {
            DataSet SetTmp = new DataSet();
            DataSet SReturn = new DataSet();
            try
            {
                string xml = path + "\\01Temp\\AV" + DateTime.Now.ToFileTime().ToString() + ".xml";
                src.WriteXml(xml);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public DataSet GetJob(string path)
        {
            DataSet SResult = new DataSet();
            DataSet SReturn = new DataSet();

            try
            {
                string fileDone;
                string filestemp = path + "\\01Temp";
                string[] files = System.IO.Directory.GetFiles(filestemp);
                foreach (string file in files)
                {
                    fileDone = file.Replace(@"\01Temp\", @"\02Incoming\");
                    System.IO.File.Move(file, fileDone);
                }
                string files2p = path + "\\02Incoming";
                files = System.IO.Directory.GetFiles(files2p);

                if (files.Length > 0)
                {
                    string file = files[0];
                    SResult.ReadXml(file);
                    SReturn.Merge(SResult);
                    fileDone = file.Replace(@"\02Incoming\", @"\03Done\");
                    System.IO.File.Move(file, fileDone);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {

            }
            return SReturn;
        }
     
    }
}